package com.bgs.eat.scheduledTasks;

import com.bgs.eat.config.CommonResult;
import com.bgs.eat.rider.entity.Riderinformation;
import com.bgs.eat.rider.mapper.riderinformationMapper;
import com.bgs.eat.utils.RedisUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.*;

@Component
@EnableScheduling
public class ScheduledTasks {

    @Autowired
    RedisUtil redisUtil;

    @Autowired
    private riderinformationMapper riderinformationMapper;

    /* *
     * @Author: beisheng
     * @Descriprion: 设置定时任务(每天24:00执行),将每日的收入和每日完成订单重置
     * @Date: 2022/10/26 14:37
     */
    @Scheduled(cron = "0 0 00 * * ?")
    public void ScheduledTask() {

        List<Riderinformation> riderinformations = riderinformationMapper.selectAll();
        for (int i = 0; i < riderinformations.size(); i++) {

            Example example = new Example(Riderinformation.class);
            Example.Criteria criteria = example.createCriteria();
            criteria.andEqualTo("id",riderinformations.get(i).getId());
            Riderinformation riderinformation = riderinformationMapper.selectOneByExample(example);
            Riderinformation xrf = new Riderinformation();
            BeanUtils.copyProperties(riderinformation,xrf);
            xrf.setOrdersNumber(null);
            xrf.setTodayMoney(null);
            riderinformationMapper.updateByExample(xrf,example);

        }
        System.out.println("======================================================");
        System.out.println("                    任务执行成功");
        System.out.println("======================================================");
    }
}
